package com.open.capacity.activity.controller;

import com.open.capacity.activity.service.ResumeActivityService;
import com.open.capacity.common.model.ResumeActivity;
import com.open.capacity.common.util.PageUtil;
import com.open.capacity.common.web.PageResult;
import com.open.capacity.common.web.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @program: open-capacity-platform
 * @description:
 * @author: bellweather
 * @create: 2021-01-19 17:26
 **/
@RestController
public class ResumeActivityController {
    @Autowired
    private ResumeActivityService resumeActivityService;


    @PutMapping("/re_acts")
    public Result save(@RequestBody ResumeActivity activity){
        int save = resumeActivityService.save(activity);
        if(save>0){
            return Result.succeed(activity.getId(),"添加成功");
        }else {
            return Result.failed("添加失败");
        }
    }

    @GetMapping("/re_acts")
    public PageResult<ResumeActivity> findList(@RequestParam Map<String,Object> params){
        PageUtil.pageParamConver(params,true);
        List<ResumeActivity> list = resumeActivityService.getList(params);
        return PageResult.<ResumeActivity>builder().code(0).count((long) list.size()).data(list).build();
    }
    @GetMapping("/re_acts/enable")
    public PageResult<ResumeActivity> findListEnable(@RequestParam Map<String,Object> params){
        PageUtil.pageParamConver(params,true);
        params.put("deleted",1);
        List<ResumeActivity> list = resumeActivityService.getList(params);
        return PageResult.<ResumeActivity>builder().code(0).count((long) list.size()).data(list).build();
    }

    @DeleteMapping("/re_acts/{id}")
    public Result delete(@PathVariable("id") long id){
        int delelte = resumeActivityService.delelte(id);
        if(delelte>0){
            return Result.succeed(id,"删除成功");
        }else {
            return Result.failed("删除失败");
        }
    }
}
